package cn.edu.zafu.bigdata.liuwenyi;

class StaticDemo {
    static int count;

    int id;

    // 静态初始化块
    static {
        System.out.println("Static block executed");
        count = 0;
    }

    // 实例初始化块
    {
        System.out.println("Instance block executed");
        id = count;
        count++;
    }

    // 构造函数
    public StaticDemo() {
        System.out.println("Constructor executed for ID: " + id);
    }

    public static void displayCount(){
        System.out.println("Total instances created:" + count);
    }

}
    public class StaticDemo_Test {
        public static void main(String[] args) {
            StaticDemo instance1 = new StaticDemo();
            StaticDemo instance2 = new StaticDemo();
            StaticDemo instance3 = new StaticDemo();

            StaticDemo.displayCount();
        }
    }